/**
* ===============================================================================================================
* Native driver for lan911x Ethernet Controller.
*
* There has nothing depedency on Operating System or upper layer protocol stack.
* Yeah, it just a pure and clean driver. You can build the TCP/IP stack based on this driver.
* ===============================================================================================================
* Reference
*
* https://ww1.microchip.com/downloads/en/DeviceDoc/00002266B.pdf
* https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ApplicationNotes/ApplicationNotes/en562758.pdf
*
* ===============================================================================================================
* Copyright (c) 2024, DY Young.
* All rights reserved.
*
* Licencse Term
*----------------
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that
* the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
*    this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
*    following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* ===============================================================================================================
*/

#include "lan911x_native.h"

/** Internal PHY Register **/
/** --------------------- **/
/** accessed by MII_ACC and MII_DATA **/
enum phy_register {
    PHY_CR      = 0x0,      // PHY Basic Control
    PHY_STATUS  = 0x1,      // PHY Basic Status
    PHY_ID1     = 0x2,
    PHY_ID2     = 0x3,
    ANA         = 0x4,      // Auto-Negotiation Advertisement
    ANLPA       = 0x5,      // Auto-Negotiation Link Partner Ability
    ANE         = 0x6,      // Auto-Negotiation Expansion
    MCSR        = 0x11,     // Mode CSR
    SMODE       = 0x12,     // Special Mode
    SCSI        = 0x1b,     // Special Control Status Indication
    ISRC        = 0x1d,     // Interrupt Source
    IMSK        = 0x1e,     // Interrupt MASK
    SCSR        = 0x1f,     // PHY Special CSR
};

U32_FEILD_START(vPHY_CR)
uint32 useless(0)   : 7;
uint32 enCOL_TEST   : 1;
uint32 Duplex       : 1;
uint32 Restart_AN   : 1;
uint32 useless(1)   : 1;
uint32 PowerDown    : 1;
uint32 enAutoNego   : 1;
uint32 speed        : 1;
uint32 loopback     : 1;
uint32 reset        : 1;
uint32  useless(2)  : 16;
U32_FEILD_STOP(vPHY_CR)


U32_FEILD_START(vPHY_ID1)
uint32 phy_id     : 16;
uint32 useless(0) : 16;
U32_FEILD_STOP(vPHY_ID1)

U32_FEILD_START(vPHY_ID2)
uint32 revision   : 4;
uint32 model      : 6;
uint32 phy_id_b   : 6;
uint32 phy_id     : 16;
U32_FEILD_STOP(vPHY_ID2)